package cn.itcast.order.sentinel;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author xph
 * @Date 2022/8/29 16:51
 * @Description: 授权规则
 */

@Component
public class HeaderOriginParser implements RequestOriginParser {

    /**
     * 判断请求来源是否带有origin
     * @param httpServletRequest
     * @return
     */
    @Override
    public String parseOrigin(HttpServletRequest httpServletRequest) {
        // 1、获取请求头
        String origin = httpServletRequest.getHeader("origin");
        // 2、非空判断
        if (StringUtils.isEmpty(origin)){
            origin = "blank";
        }
        return origin;
    }
}
